
import { _decorator, Component, Node, PhysicsSystem, Collider, ITriggerEvent, tween, MeshRenderer, Vec3, Vec4, RigidBody, game, director, isValid, Enum } from 'cc';
import GEnum from '../../module_basic/scripts/config/GEnum';
const { ccclass, property } = _decorator;
@ccclass('PocketTrigger')
export class PocketTrigger extends Component {
    public static EVENT_HIT_POCKET = 'PocketTrigger.hit_pocket';
    //#region 组件第一次激活前执行，也就是第一次执行 update 之前触发
    start () {
        this.initListener();
    }
    //#endregion

    //#region 初始化碰撞发生的监听
    initListener () {
        this.getComponent(Collider).on("onTriggerEnter", this.onTriggerEnter);
    }
    //#endregion

    //#region 碰撞发生时执行的回调
    onTriggerEnter (triggerEvent: ITriggerEvent) {
        console.log("adfsadf");
        if (triggerEvent.otherCollider.getGroup() === GEnum.ColliderGroup.BALL) {
            var ballCollider = triggerEvent.otherCollider;
            director.getScene().emit(PocketTrigger.EVENT_HIT_POCKET,ballCollider.node);
        }
    }
}